package phoenix.web.page_objects.backend;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.PageBaseWebExt;
import phoenix.web.locators.backend.IndexPageLocators;

/**
 * Class provides the methods for Index page (backend)
 */
public class IndexPage extends PageBaseWebExt
{
	/**
	 * Initializes the IndexPage
	 * @param p_manager PhoenixManager instance
	 */
	public IndexPage(PhoenixManager p_manager)
	{
		super(p_manager);
	}

	/**
	 * Gets web elements by site
	 * @return IndexPageLocators instance
	 */
	public IndexPageLocators elements()
	{
		return new phoenix.web.locators.backend.IndexPageLocators();
	}

	/**
	 * Logins to the site backend
	 */
	public void login()
	{
		wd().openURL(manager.config().BACKEND_URL_BASE);

		if (wd().isElementPresent(manager.backend().userMenu().elements().blockUserMenu))
		{
			log().info("Already logged in admin panel");
		}
		else
		{
			wd().waitForPresence(elements().txtLogin, "Login field doesn't appear");
			wd().type(elements().txtLogin, manager.config().BACKEND_USERNAME);
			wd().type(elements().txtLoginPassword, manager.config().BACKEND_PASSWORD);
			wd().click(elements().btnLogin);
			wd().waitForPresence(manager.backend().userMenu().elements().blockUserMenu, "Backend left menu doesn't appear");
		}
	}
}
